<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>打印菱形</title>
    <style type="text/css">
        div {
            text-align: center;
            line-height: 25px;
        }
    </style>
</head>
<body>
<div>
    <script>
        var t = prompt("请输入要打印菱形的行数：", "");
        if (t > 0) {
            for (var i = 0; i < t; i++) {
                document.write(" ");
                for (j = 0; j <= i; j++) {
                    document.write("*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                }
                document.write("<br>");
            }

            for (var i = t; i > 0; i--) {
                document.write(" ");
                for (j = 1; j < i; j++) {
                    document.write("*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                }
                document.write("<br>");
            }
        } else {
            alert("你输入的行数不合法！");
        }
    </script>
</div>
</body>
</html>